package com.foreknow.service.impl;

import com.foreknow.dao.impl.AdminDAOImpl;
import com.foreknow.db.DBManager;
import com.foreknow.model.Admin;
import com.foreknow.service.AdminService;

import java.sql.Connection;
import java.sql.SQLException;

public class AdminServiceImpl implements AdminService {
    @Override
    public Admin isValidate(String username, String password) {
        DBManager dbManager = DBManager.getInstance();
        Connection conn = dbManager.getConnection();

        AdminDAOImpl adminDAO = new AdminDAOImpl();
        adminDAO.setConnection(conn);
        Admin admin = null;
        try {
          admin = adminDAO.isCheckLogin(username, password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return admin;
    }

    @Override
    public boolean getUsernmaeByUser(String username) {
        DBManager dbManager = DBManager.getInstance();
        Connection connection = dbManager.getConnection();
        AdminDAOImpl adminDAO = new AdminDAOImpl();
           adminDAO.setConnection(connection);
       boolean isRight =false;
        try {
           isRight =adminDAO.getUsernmaeByUser(username);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return isRight;
    }
}
